#include <iostream>
#include <memory>
using namespace std;
class Person
{
public:
    Person()
    {
        cout<<"Person()"<<endl;
    }
    ~Person()
    {
        cout<<"~Person()"<<endl;
    }
public:
    void run()
    {
        cout<<"person run()"<<endl;
    }
private:
    int m_age;
};

template<typename T>
class smartPtr
{
public:
    smartPtr(T * obj)
    {
        ptr = obj;
        // cout<<"smartPtr()"<<endl;
    }
    ~smartPtr()
    {
        delete ptr;
        // cout<<"~smartPtr()"<<endl;
    }

public:
    T * operator->()
    {
        return ptr;
    }
private:
    T * ptr;

};

int main()
{
    // {
    //     Person * p2 = new Person;
    //     p2->run();
    //     /*只有调用delete才会调用析构*/
    //     delete p2;
    // }
#if 0
    {
        /*auto_ptr 的使用*/
        auto_ptr<Person> p1(new Person);
        p1->run();
        /*auto_ptr 的使用 不适用于数组*/

    }
#endif

#if 0
    smartPtr<Person> sp(new Person);
    sp->run();
#endif

#if 1
    {
        #if 1
        {
            shared_ptr<Person> p2(new Person);
            shared_ptr<Person> p3(new Person);

            {
                shared_ptr<Person> p1(new Person);
                p2 = p1;
                cout<<"cout"<<p1.use_count()<<endl;
            }
            cout<<"cout"<<p2.use_count()<<endl;
            cout<<"2222"<<endl;
            p3 = p2;
            cout<<"cout"<<p3.use_count()<<endl;
        }
        cout<<"3333"<<endl;

        #endif

        // shared_ptr<Person> psh(new Person);
        // psh->run();
        // /*是否使用于数组*/
        // shared_ptr<Person> psh2(new Person);


    }
#endif
    return 0;
}